<?php
/**
 * Created by PhpStorm.
 * User: Haima
 * Date: 2018/7/8
 * Time: 15:58
 */

namespace app\api\controller\v1;
use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\BannerMissException;

class Banner
{
    /**
     * 获取指定id的banner信息
     * @url /banner/:id
     * @http GET
     * @id banner的id号
     */
    public function getBanner($id)
    {

        (new IDMustBePostiveInt())->goCheck(); //验证$id是否为正整数
        $banner = BannerModel::getBannerById($id);//调用model
        if (!$banner){
           throw new BannerMissException(); //判断结果不存在,抛出异常
        }
        return json($banner,200);//返回json格式的结果, 默认就是200状态码,可不写
    }
}